package py.com.fms.session;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;

import py.com.fms.exception.CommonException;
import py.com.fms.fms.bean.BranchBean;
import py.com.fms.fms.bean.CountryBean;
import py.com.fms.fms.bean.CurrencyBean;
import py.com.fms.fms.bean.EnterpriseBean;
import py.com.fms.fms.bean.GenParamBean;
import py.com.fms.fms.persistence.services.BranchServices;
import py.com.fms.fms.persistence.services.CountryServices;
import py.com.fms.fms.persistence.services.CurrencyServices;
import py.com.fms.fms.persistence.services.EnterpriseServices;
import py.com.fms.fms.persistence.services.GenParamServices;
import py.com.fms.utilities.ConvertAssistant;


@Name("paramHolder")
@Scope(ScopeType.APPLICATION)
public class ParamHolder {
	
	@Logger
	private Log log;
	@In("#{serviceSqlMap}")
	private ServiceSqlMap sqlMap;
	@In("#{convertAssist}")
	private ConvertAssistant convert;
	
	private EnterpriseBean ent;
	private BranchBean branch;
	private CountryBean country;
	private CurrencyBean currency;
	private String percentType;
	
	private GenParamBean param;
	
	private GenParamServices gpSrv;

	
	public void initData() throws CommonException{
		
		this.initObjects();
		
	}
	
	public void initObjects() throws CommonException{
		
		if(sqlMap == null){
			sqlMap = new ServiceSqlMap();
		}
		
		if(ent == null){
			ent = new EnterpriseBean(); 
		}
		
		if(branch == null){
			branch = new BranchBean(); 
		}
		
		if(country == null){
			country = new CountryBean(); 
		}
		
		if(currency == null){
			currency = new CurrencyBean(); 
		}
		
		if(percentType == null){
			percentType = new String(); 
		}
		
		if(param == null){
			param = new GenParamBean(); 
		}
		
		if(gpSrv == null){
			gpSrv = new GenParamServices(this.sqlMap.getConfig()); 
		}
		
		if(convert == null){
			convert = new ConvertAssistant(); 
		}
		
	}
	
	
	public void loadParams() throws CommonException{
		BranchServices brSrv = new BranchServices(this.sqlMap.getConfig());
		CurrencyServices crSrv = new CurrencyServices(this.sqlMap.getConfig());
		CountryServices cnSrv = new CountryServices(this.sqlMap.getConfig());
		EnterpriseServices enSrv = new EnterpriseServices(this.sqlMap.getConfig());
		
		Long branchId = new Long(0);
		Long currencyId = new Long(0);
		Long countryId = new Long(0);
		Long entId = new Long(0);
		
//		// Load Branch
//		branchId = convert.stringToLong(gpSrv.getGenParamValue("SUC"));
//		this.setBranch(brSrv.getBranchById(branchId));
//		
//		// Load Currency
//		currencyId = convert.stringToLong(gpSrv.getGenParamValue("MON"));
//		this.setCurrency(crSrv.getCurrencyData(currencyId));
//		
//		// Load Country
//		countryId = convert.stringToLong(gpSrv.getGenParamValue("PAIS"));
//		this.setCountry(cnSrv.getCountryById(countryId));
//		
//		// Load Enterprise
//		entId = convert.stringToLong(gpSrv.getGenParamValue("EMP"));
//		this.setEnt(enSrv.getEntById(entId));
//		
//		// Load Percent Type
//		this.setPercentType(gpSrv.getGenParamValue("PERC"));
	}
	
	
	// GETTERS AND SETTERS
	
	public Log getLog() {
		return log;
	}

	public void setLog(Log log) {
		this.log = log;
	}

	public ServiceSqlMap getSqlMap() {
		return sqlMap;
	}

	public void setSqlMap(ServiceSqlMap sqlMap) {
		this.sqlMap = sqlMap;
	}

	public EnterpriseBean getEnt() {
		return ent;
	}

	public void setEnt(EnterpriseBean ent) {
		this.ent = ent;
	}

	public BranchBean getBranch() {
		return branch;
	}

	public void setBranch(BranchBean branch) {
		this.branch = branch;
	}

	public CountryBean getCountry() {
		return country;
	}

	public void setCountry(CountryBean country) {
		this.country = country;
	}

	public CurrencyBean getCurrency() {
		return currency;
	}

	public void setCurrency(CurrencyBean currency) {
		this.currency = currency;
	}

	public String getPercentType() {
		return percentType;
	}

	public void setPercentType(String percentType) {
		this.percentType = percentType;
	}

	public GenParamBean getParam() {
		return param;
	}

	public void setParam(GenParamBean param) {
		this.param = param;
	}
	
	
	
	
}
